package com.wzy.orderSystem.controller;

import com.wzy.orderSystem.pojo.user;
import com.wzy.orderSystem.service.impl.opUserImpl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class userController {
   private static opUserImpl oul =  new opUserImpl();

    //根据id查询用户信息
    public static void selectById(int id){
        System.out.println("用户id为"+id+"信息如下：");
        try {
            List<user> users = oul.selectById(id);
            for (user u : users){
                System.out.println("用户id:"+u.getId());
                System.out.println("用户姓名:"+u.getUsername());
                System.out.println("用户密码:"+u.getPassword());
                System.out.println("用户电话:"+u.getPhone());
                System.out.println("用户昵称:"+u.getNickName());
                System.out.println("用户状态:"+u.getUserState());
                System.out.println("用户注册时间:"+u.getNowLogin());
                System.out.println("用户最后登录时间:"+u.getLastLogin());
                System.out.println("用户地址:"+u.getUserAddress());
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }

    //根据id修改用户密码
    public static void updateById(int id,String password){
        int i = oul.updateById(id, password);
        System.out.println(i>0?"修改成功！":"修改失败");
    }

    //根据id删除用户
    public static void deleteById(int id){
        int i = oul.deleteById(id);
        System.out.println(i>0?"删除成功！":"删除失败");
    }

    //增加用户
    public static void insert(int id, String username, String password, String phone, String nickName , String  userState, Date nowLogin,Date laseLogin,String address){
        int i = oul.insert(id,username, password,phone,nickName,userState,nowLogin,laseLogin,address);
        System.out.println(i>0?"新增成功！":"新增失败");
    }
}
